package uk.ac.lkl.common.util;



import java.util.EventListener;

import javax.swing.event.EventListenerList;


/**
 * 
 * 
 * @author Darren Pearce
 * @version $Revision: 358 $
 * @version $Date: 2007-10-30 16:17:18 +0000 (Tue, 30 Oct 2007) $
 * 
 */
public abstract class AbstractEventSupport<L extends EventListener> {

    protected final Object source;

    protected final Class<L> listenerClass;


    protected AbstractEventSupport(Object source) {
        this.source = source;
        this.listenerClass = getListenerClass();
    }


    protected abstract Class<L> getListenerClass();


    /**
     * Get the source of the events.
     * <p>
     * 
     * @return the source of the events
     */
    public final Object getSource() {
        return source;
    }


    /**
     * Return an array of all the listeners of the appropriate type in the list.
     * 
     * 
     */
    protected L[] getListeners(EventListenerList listenerList) {
        return listenerList.getListeners(listenerClass);
    }

}
